package com.ruoyi.system.filter;

import lombok.extern.log4j.Log4j2;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.http.HttpMethod;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @author 姚炜琦
 * @Classname LogFilter
 * @Description TODO
 * @Date 2022/8/9 9:45
 */
@Configuration
@Log4j2
public class LogFilter implements GlobalFilter, Ordered {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        ServerHttpRequest request = exchange.getRequest();
        String path = request.getURI().getPath();
        HttpMethod method = request.getMethod();
        log.info("开始网关过滤 请求地址：【{}】，请求方法：【{}】",path,method);
        return chain.filter(exchange);
    }

    @Override
    public int getOrder() {
        return -1;
    }
}
